'use strict';

var nativeButtonBehavior = require('./native-button-behaviors');

Component({
    externalClasses: ['custom-class'],
    behaviors: [nativeButtonBehavior],
    relations: {
        '../btn-group/index': {
            type: 'parent',
            linked: function linked() {
                this.setData({ inGroup: true });
            },
            unlinked: function unlinked() {
                this.setData({ inGroup: false });
            }
        }
    },
    properties: {
        type: {
            type: String,
            value: ''
        },
        _style: {
            type: String,
            value: ''
        },
        formType: {
            type: String,
            value: ''
        },
        size: {
            type: String,
            value: ''
        },
        plain: {
            type: Boolean,
            value: false
        },
        disabled: {
            type: Boolean,
            value: false
        },
        loading: {
            type: Boolean,
            value: false
        }
    },

    data: {
        inGroup: false,
        isLast: false
    },

    methods: {
        handleTap: function handleTap() {
            if (this.data.disabled) {
                this.triggerEvent('disabledclick');
                return;
            }
            this.triggerEvent('btnclick');
        },
        switchLastButtonStatus: function switchLastButtonStatus() {
            var isLast = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;

            this.setData({ isLast: isLast });
        },
        formSubmit: function (e) {
            console.log('form发生了submit事件，携带数据为：', e.detail)
            this.triggerEvent('reportSubmit', e.detail);
        }
    }
});